Skip to content

draft impl for indexstore-powered improved highlights #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 1, 2024

Conversation

tayloraswift
Copy link
Owner

@tayloraswift tayloraswift commented May 30, 2024

this PR adds most of the logic needed for improved IndexStoreDB syntax highlighting, gated behind the build-time UNIDOC_ENABLE_INDEXSTORE=1 environment variable.

this violates our longstanding ban on the Foundation dependency, but all the alternatives seemed patently stupid. (and it’s not like importing Foundation in the manifest could cause any problems in the first place.)

for unknown reasons, our IndexStoreDB intergration is unable to emit symbol information for symbols outside the current SwiftPM Snippet, which is our principal use case. so the feature will be of very little impact until that issue is resolved. that issue will be tracked in #246

@tayloraswift
Copy link
Owner Author

so there’s a weird issue in that we seem to be getting symbol occurrence information from IndexStoreDB, but it is somewhat limited, and not particularly “LSP-like”. in particular, we are not seeing resolutions for standard library symbols (e.g. Int), and moreover, we are not seeing resolutions for types in identifier positions like let x = E().

@tayloraswift
Copy link
Owner Author

tayloraswift commented May 31, 2024

after doing some more investigation, it seems we have at least two possibly unrelated issues

  1. IndexStoreDB is not emitting any information about standard library symbols (e.g. Int) whatsoever.

  2. IndexStoreDB is labeling the type name as phylum = init when using implicit static init syntax (e.g. Foo() where Foo is a type.)

    this is correct as a link target, because when we click on such a token, we expect to be taken to the initializer and not the type itself. but because the SymbolOccurrence looks identical ([ref|call|calledBy|contBy]) to an explicit Foo.init() call, it receives the wrong token coloring.

    this problem only occurs if the type declares a physical init, if it only has synthesized inits the token receives the correct coloring.

the second issue we can probably get around with the right heuristics, but the first one is a major blocker. it seems IndexStoreDB is only including information about symbols in the same module, which for a snippet, is the snippet itself. could we be initializing the IndexStoreDB instance wrong?

func indexStore(for swift:SSGC.Toolchain) throws -> (any Markdown.SwiftLanguage.IndexStore)?

here is an annotated illustration of the problems in the test snippet:

image

@tayloraswift tayloraswift self-assigned this May 31, 2024
@tayloraswift tayloraswift merged commit b35fbe2 into master Jun 1, 2024
2 checks passed
@tayloraswift tayloraswift deleted the indexstore-highlighting branch June 1, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant